'use strict';

const db = uniCloud.database()
const categoriesCollection = db.collection('categories')

exports.main = async (event, context) => {
	try {
		// 获取所有分类，按创建时间倒序排序
		const res = await categoriesCollection
			.orderBy('createTime', 'desc')
			.get()
			
		return {
			code: 0,
			msg: '获取成功',
			data: res.data
		}
	} catch (error) {
		console.error('获取分类列表失败', error)
		return {
			code: -1,
			msg: '获取分类列表失败'
		}
	}
} 